import React from 'react';
import {
  BrowserRouter as Router,
  Route
} from 'react-router-dom';
import Home from '../components/index/index.jsx'; // 首页
import Download from '../components/index/download.jsx'; //下载页
import Login from '../components/index/login/login.jsx'; //登录
import ResetPwd from '../components/index/login/resetPwd.jsx'; //重置密码
import Register from '../components/index/login/register.jsx'; //注册
import Agreement from '../components/index/login/agreement.jsx'; //注册协议
import Search from '../components/index/search/search.jsx'; //搜索
import SearchProductbig from '../components/index/search/searchProductbig.jsx'; //搜索产品
import SearchCompany from '../components/index/search/searchCompany.jsx'; //搜索公司
import Company from '../components/index/company/company.jsx'; //店铺
import Companyclassify from '../components/index/company/companycontent/companyclassify.jsx'; //店铺商品分类
import ClassifyList from '../components/index/company/companycontent/classifyList.jsx'; //店铺分类展示
import Auth from '../components/index/company/companycontent/companyFile/auth.jsx'; //店铺证书
import ShopDetail from '../components/shop/shopDetail.jsx'; //商品详情
import User from '../components/user/user.jsx'; //个人中心
import Order from '../components/user/order/order.jsx'; //订单管理
import Orderlist from '../components/user/order/orderlist.jsx'; //订单详情
import ConOrder from '../components/user/order/conOrder.jsx'; //确认订单
import CallbackPage from '../components/user/order/callbackPage.jsx'; //支付回调页
import Logistics from '../components/user/order/logistics.jsx'; //物流
import ShipAddress from '../components/user/shipAddress/shipAddress.jsx'; //收货地址
import EditAddress from '../components/user/shipAddress/editAddress.jsx'; //编辑地址
import AddAddress from '../components/user/shipAddress/addAddress.jsx'; //添加地址
import Message from '../components/user/message/message.jsx'; //通知中心
import SystemInfo from '../components/user/message/system/systemInfo.jsx'; //公告详情
import Collect from '../components/collect/collect.jsx'; //收藏夹
import News from '../components/news/news.jsx'; //资讯
import Notice from '../components/news/notice/notice.jsx'; //资讯详情
import Classify from '../components/classify/classify.jsx'; //三级分类
import ClassifyProductbig from '../components/classify/classifyProductbig.jsx'; //分类商品展示
import Trade from '../components/trade/trade.jsx'; //行业市场
import Cart from '../components/cart/cart.jsx'; //进货单
import Errorpage from '../components/widget/error.jsx'; //404页面

const routes = [ // 构建全局路由
  {
    path: '/', // 父路由
    component: Home
  }, {
    path: '/download',
    component: Download
  }, {
    path: '/login',
    component: Login
  }, {
    path: '/resetPwd',
    component: ResetPwd
  }, {
    path: '/register',
    component: Register
  }, {
    path: '/register/agreement',
    component: Agreement
  }, {
    path: '/search',
    component: Search
  }, {
    path: '/search/searchProductbig',
    component: SearchProductbig
  }, {
    path: '/search/searchCompany',
    component: SearchCompany
  }, {
    path: '/company',
    component: Company
  }, {
    path: '/company/companyclassify',
    component: Companyclassify
  }, {
    path: '/company/classifyList',
    component: ClassifyList
  }, {
    path: '/company/auth',
    component: Auth
  }, {
    path: '/shopDetail',
    component: ShopDetail
  }, {
    path: '/collect',
    component: Collect
  }, {
    path: '/user',
    component: User
  }, {
    path: '/user/order',
    component: Order
  }, {
    path: '/user/order/orderlist',
    component: Orderlist
  }, {
    path: '/user/order/conOrder',
    component: ConOrder
  }, {
    path: '/user/order/callbackPage',
    component: CallbackPage
  }, {
    path: '/user/order/logistics',
    component: Logistics
  }, {
    path: '/user/shipAddress',
    component: ShipAddress
  }, {
    path: '/user/shipAddress/editAddress',
    component: EditAddress
  }, {
    path: '/user/shipAddress/addAddress',
    component: AddAddress
  }, {
    path: '/user/message',
    component: Message
  }, {
    path: '/user/message/systemInfo',
    component: SystemInfo
  }, {
    path: '/news',
    component: News
  }, {
    path: '/news/notice',
    component: Notice
  }, {
    path: '/trade',
    component: Trade
  }, {
    path: '/classify',
    component: Classify
  }, {
    path: '/classifyProductbig',
    component: ClassifyProductbig
  }, {
    path: '/Cart',
    component: Cart
  }, {
    path: '/errorpage',
    component: Errorpage
  }
]

const RouteWithSubRoutes = (route) => (
<Route path={route.path} exact render={props => (
    // pass the sub-routes down to keep nesting
      <route.component {...props} routes={route.routes}/>
)
}
/>
)
class BasicExample extends React.Component {
  updateHandle() {
    console.log('每次router变化之后都会触发')
  }
  render() {
    return (
      <Router onUpdate={this.updateHandle.bind(this)}>
        <div className='main-content'>
          <div className='clearfix'>
            {
              routes.map((route, i) => (
                <RouteWithSubRoutes key={i} {...route}/>
              ))
            }
          </div>
        </div>
      </Router>
    )
  }
}



export default BasicExample